package com.gxa.admin.controller;

import com.gxa.admin.param.UserParam;
import com.gxa.admin.service.CategoryService;
import com.gxa.o2o.core.dto.ResultDTO;
import com.gxa.o2o.core.pojo.Category;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "后台----分类管理")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    @ApiOperation(value = "查询所有分类（未被删除的）")
    @PostMapping("/listAll")
    public ResultDTO listAll(){
        return categoryService.listAll();
    }

    @PostMapping("/listByParam")
    @ApiOperation(value = "通过条件分页查询（包括已被删除的）")
    public ResultDTO listByParam(UserParam param){
        return categoryService.listByParam(param);
    }

    @PostMapping("/addOne")
    @ApiOperation(value = "添加分类")
    public ResultDTO addOne(Category category){
        return categoryService.add(category);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除（包括批量删除）,传入数组(ids),json传参")
    public ResultDTO delete(@RequestBody  List<Integer> ids){
        return categoryService.delete(ids);
    }

    @PostMapping("/updateOne")
    @ApiOperation(value = "修改分类（分类名和类别id必传）")
    public ResultDTO updateOne(Category category){
        return categoryService.updateOne(category);
    }
}
